import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404.vue'),
    hidden: true
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: {
          title: 'Dashboard',
          icon: 'dashboard',
          // 如果设置为true，它则会固定在tags-view中(默认 false)
          affix: true
        }
      }

    ]
  },
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: 'disposition',
        component: () => import('@/views/disposition/disposition.vue'),
        name: 'disposition',
        meta: {
          title: '模块配置',
          icon: 'dashboard',

          // 设置该路由进入的权限，支持多个权限叠加
          roles: ['admin', 'editor']
        }
      }

    ]
  }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
